var VOID = 0
var ADMIN = 1
var DEVELOPER = 2
var USER = 3

function transform(config) {
  if (config == null) return false
  else return true
}

const getters = {
  /*
    前端
   */
  sidebar: state => state.app.sidebar,
  device: state => state.app.device,
  appDetailId: state => state.application.appDetailId,
  methodologyFrom: state => state.application.methodologyFrom,
  language: state => state.app.language,

  /*
    用户
  */
  token: state => state.user.token,
  avatar: state => state.user.avatar,
  group: state => state.user.group, // 用户组 id
  id: state => state.user.id, // 用户 id
  name: state => state.user.name, // 用户名

  // k8s
  template_server_available: state => transform(state.user.system_config.k8s.template_server),
  template_server: state => state.user.system_config.k8s.template_server,

  /*
    权限鉴别
  */
  // 当前登陆账号
  isAdmin: (state) => () => { return state.user.group === ADMIN }, // 判断当前登陆用户是否是管理员
  isDeveloper: (state) => () => { return state.user.group === DEVELOPER }, // 判断当前登陆用户是否是开发者
  isUser: (state) => () => { return state.user.group === USER }, // 判断当前登陆用户是否是普通用户
  isVoid: (state) => () => { return state.user.group !== ADMIN && state.user.group !== DEVELOPER && state.user.group !== USER }, // 判断当前登陆用户是否是 void 组

  // 查询某一账号
  isSelf: (state) => (id) => { return state.user.id === id }, // 传入 user.id 判断是否是自己
  isAdminGroup: (state) => (id) => { return id === ADMIN }, // 传入 group.id 判断id是否是超级管理员组
  isDeveloperGroup: (state) => (id) => { return id === DEVELOPER }, // 传入 group.id 判断id是否是开发者组
  isUserGroup: (state) => (id) => { return id === USER }, // 传入 group.id 判断id是否是普通用户组
  isVoidGroup: (state) => (id) => { return id !== ADMIN && id !== DEVELOPER && id !== USER }, // 传入 user.id 判断是否是void组

  // 根据 group_id 获取用户组名称
  getGroupNameById: (state) => (id) => {
    if (id === ADMIN) return '管理员'
    else if (id === DEVELOPER) return '开发者'
    else if (id === USER) return '用户'
    else return '无用户组'
  },

  roles: (state) => {
    // 假设 group_id 对应的角色名称映射在一个对象中
    const roleMap = {
      1: 'admin'
    }
    return [roleMap[state.user.group]]
  }
}
export default getters
